var jsonObjEquals = require('./jsonObjEquals');
/**
 * 找到在arr中obj的下标，无则返回-1
 * @param {Object} obj
 * @param {Array} arr
 * @returns {int}
 */
function arrIndexOfObj(obj, arr) {
    if(obj && arr && arr instanceof Array) {
        for(var o in arr) {
            if(jsonObjEquals(arr[o], obj) === true ) {
                return Number(o);
            }
        }
    }
    return -1;
}

var obj1 = {"name":"user1", "old":1};
var obj2 = {"old":2, "name":"user2"};
var obj3 = {"old":3};
var obj4 = {"name":"user4"};
var arr = [obj1, obj2, obj3, obj4];
var obj5 = {"name":"user4"};

console.log(arrIndexOfObj(obj5, arr))

module.exports = arrIndexOfObj